package com.xbongbong.pro.statistics.help;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.pro.domain.entity.ChartEntity;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author 李翔
 * @date 2023/2/1
 * @description
 */
@Component
public class WorkOrderV2CustomChartHelper {

    /**
     * @param chartEntity chartEntity
     * @return 版本Id
     */
    public Integer getVersionId(ChartEntity chartEntity){
        Integer res = -1;
        JSONArray filterArray = chartEntity.getFilter();
        for (Object o : filterArray) {
            JSONObject filterObject = (JSONObject)JSONObject.toJSON(o);
            String attr = filterObject.getString("attr");
            if (Objects.equals(attr, "versionId")) {
                res = filterObject.getJSONArray("value").getInteger(0);
            }
        }
        return res;
    }

}
